package main

import (
	"fmt"
	"sync"
)

func f1(ch chan int) {
	
	for i := 0; i < 100; i++ {
		//wg.Add(i)
		ch <- i
	}
	close(ch)
	//defer wg.Done()
}

var wg sync.WaitGroup

func f2(ch1,ch2 chan int)  {
// for a:=range ch1{
// 	ch2<-a*a
// }
	for {
		a,ok:=<-ch1
		if !ok{
			break
			//defer wg.Done()
		}
		ch2<-a*a
	}
	close(ch2)
}

func main() {
	//wg.Add(1)
	ch1 := make(chan int ,50)
	ch2 :=make (chan int ,100)
	go	f1(ch1)
	go	f2(ch1,ch2)
	for a:=range ch2{
		fmt.Println(a)
	}
	//wg.Wait()
	
}